#导入模块
import tkinter as tk
import math
import threading
import _thread
W=tk.W
count=0
#str1=tk.StringVar()
#定义函数

def e(x,y): #按钮触发函数
 
       for b in range(1,100000):
           a(b)      

def a(n): #计算质数
    global count
    if n > 1:       
        for i in range(2,int(math.sqrt(n))+1):
            if  (n % i)== 0:
                 return          
        listb.insert(0,str(n))
        count+=1
        if count%100==0:
            lista.insert(0,"100")
    else:
         return

def g():   
    try:
        _thread.start_new_thread( e ,("Thread-2", 4, ) ) #另一个线程执行
   
    except:
        print ("Error: 无法启动线程")


#窗口
window = tk.Tk()
window.title("质数计算程序")
window.geometry("700x500")
window.resizable(0,0)
label=tk.Label(window,text='质数计算程序',bg="white",font=('Arial',12))
listb  =tk.Listbox(window)          
lista = tk.Listbox(window)
b=tk.Button(window,text="计算",command=g)

#放置
listb.place(x=40,y=160, anchor=W, width=120, height=200)                   
lista.place(x=240,y=160, anchor=W, width=120, height=200)
label.place(x=420,y=80, anchor=W, width=120, height=40)
b.place(x=420,y=160, anchor=W, width=120, height=40)



window.mainloop()
